package com.atguigu.medicalsugar.mapper;

import com.atguigu.medicalsugar.bean.PatientBean;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author lzc
 * @Date 2023/5/29 09:56
 */
public interface PatientMapper {
    @Select("select \n" +
        "    date,\n" +
        "    sum(register_ct) register_ct,\n" +
        "    sum(active_ct) active_ct,\n" +
        "    sum(new_active_ct) new_active_ct\n" +
        "from(\n" +
        "    SELECT\n" +
        "        #{date} AS date,\n" +
        "        sum(register_ct) AS register_ct,\n" +
        "        0 AS active_ct,\n" +
        "        0 AS new_active_ct\n" +
        "    FROM dws_doctor_register_window\n" +
        "    WHERE toYYYYMMDD(stt) = #{date}\n" +
        "    UNION ALL\n" +
        "    SELECT\n" +
        "        #{date} AS date,\n" +
        "        0 AS register_ct,\n" +
        "        sum(active_ct) AS active_ct,\n" +
        "        0 AS new_active_ct\n" +
        "    FROM dws_doctor_active_window\n" +
        "    WHERE toYYYYMMDD(stt) = #{date}\n" +
        "    UNION ALL\n" +
        "    SELECT\n" +
        "        #{date} AS date,\n" +
        "        0 AS register_ct,\n" +
        "        0 AS active_ct,\n" +
        "        sum(new_active_ct) AS new_active_ct\n" +
        "    FROM dws_doctor_new_active_window\n" +
        "    WHERE toYYYYMMDD(stt) = #{date}\n" +
        ")tmp\n" +
        "group by date")
    List<PatientBean> patient(Integer date);
}
